package com.example.javabasic.thread.classtwo.countdown.demo2;

import java.util.Random;
import java.util.stream.IntStream;

public class Test {

    public static void main(String[] args) {
        CountDown countDown = new CountDown(5);
        IntStream.rangeClosed(1,5).forEach(i->{
            new Thread(()->{
                try {
                    Thread.sleep(new Random(System.currentTimeMillis()).nextInt(1000));
                    System.out.println(Thread.currentThread().getName()+":执行完成:");
                    countDown.down();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();
        });
        countDown.await();
        System.out.println("全都执行完了");
    }
}
